package com.cmc.cloud.cmclink.doc.controller.admin.si;

import com.cmc.cloud.cmclink.doc.constants.UrlConstants;
import com.cmc.cloud.cmclink.doc.entity.BlnoCntrDO;
import com.cmc.cloud.cmclink.doc.entity.BlnoLocalChargeDO;
import com.cmc.cloud.cmclink.doc.entity.CalculateOperateLogDO;
import com.cmc.cloud.cmclink.doc.mapper.BlnoLocalChargeMapper;
import com.cmc.cloud.cmclink.doc.service.si.BlnoLocalChargeService;
import com.cmc.cloud.cmclink.doc.vo.blnochargevo.BlnoLocalChargeResultVO;
import com.cmc.cloud.cmclink.doc.vo.blnolocalchargevo.*;
import com.cmes.framework.biz.advice.annotations.UseResponsePropertyAdvice;
import com.cmes.framework.common.pojo.CommonResult;
import com.cmes.framework.operatelog.core.annotations.OperateLog;
import com.cmes.framework.operatelog.core.enums.OperateTypeEnum;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;

/**
 * Local Charge费用前端接口Controller
 *
 * @author codegen
 */
@Tag(name = "管理后台 - Local Charge费用")
@RestController
@Validated
@RequestMapping(UrlConstants.APPLICATION_URL + "/localCharge")
public class BlnoLocalChargeController {

    @Resource
    private BlnoLocalChargeService blnoLocalChargeService;

    @Resource
    private BlnoLocalChargeMapper blnoLocalChargeMapper;

    @Operation(summary = "多式联运查询Blno info")
    @PostMapping("/query/multi")
    @UseResponsePropertyAdvice
    @OperateLog(name = "multi local charge 计算主信息查询", type = OperateTypeEnum.GET)
    //@PreAuthorize("@ss.hasPermission({'doc:caculate:search','doc:agentslocal:search'})")
    public CommonResult<List<MultiBlnoLocalChargeRespVO>> getMultiBlnoInfo(@Valid @RequestBody MultiBlnoLocalChargeReqVO multiBlnoLocalChargeReqVo) {
        return CommonResult.success(blnoLocalChargeService.getMultiBlnoInfo(multiBlnoLocalChargeReqVo));
    }

    @Operation(summary = "查询Blno info")
    @PostMapping("/query")
    @UseResponsePropertyAdvice
    @PreAuthorize("@ss.hasPermission({'doc:caculate:search','doc:agentslocal:search'})")
    @OperateLog(name = "查询提单信息", type = OperateTypeEnum.GET)
    public CommonResult<List<BlnoLocalChargeRespVO>> getBlnoInfo(@Valid @RequestBody BlnoLocalChargeReqVO localChargeReqVo) {
        return CommonResult.success(blnoLocalChargeService.getBlnoInfo(localChargeReqVo));
    }

    @Operation(summary = "查询Local charge 信息")
    @GetMapping("/detail/{blId}/{imExType}")
    @OperateLog(name = "查询Local charge 信息", type = OperateTypeEnum.GET)
    @PreAuthorize("@ss.hasPermission({'doc:caculate:search','doc:agentslocal:search'})")
    public CommonResult<List<BlnoLocalChargeDetailRespVO>> getLocalChargeDetail(@PathVariable("blId") Long blId, @PathVariable("imExType") String imExType) {
        return CommonResult.success(blnoLocalChargeService.getLocalChargeDetail(blId, imExType));
    }

    @Operation(summary = "查询Local charge detail信息")
    @GetMapping("/detail/cntr/{blId}/{imExType}")
    @OperateLog(name = "查询Local charge detail信息", type = OperateTypeEnum.GET)
    @PreAuthorize("@ss.hasPermission({'doc:caculate:search','doc:agentslocal:search'})")
    public CommonResult<List<BlnoLocalChargeDetailCntrRespVO>> getLocalChargeDetailWithCntr(@PathVariable("blId") Long blId, @PathVariable("imExType") String imExType) {
        return CommonResult.success(blnoLocalChargeService.getLocalChargeDetailWithCntr(blId, imExType));
    }

    @Operation(summary = "查询Calculate log 信息")
    @GetMapping("/log/{blNo}/{imExType}")
    @OperateLog(name = "查询Calculate log 信息", type = OperateTypeEnum.GET)
    @PreAuthorize("@ss.hasPermission({'doc:caculate:search','doc:agentslocal:search'})")
    public CommonResult<CalculateOperateLogDO> getCalculateLogInfo(@PathVariable("blNo") String blNo, @PathVariable("imExType") String imExType) {
        return CommonResult.success(blnoLocalChargeService.getCalculateLogInfo(blNo, imExType));
    }

    @Operation(summary = "查询箱信息")
    @GetMapping("/cntr/{blId}")
    @OperateLog(name = "查询箱信息", type = OperateTypeEnum.GET)
    @PreAuthorize("@ss.hasPermission({'doc:caculate:search','doc:agentslocal:search'})")
    public CommonResult<List<BlnoCntrDO>> getBlNoCntrInfo(@PathVariable("blId") Long blId) {
        return CommonResult.success(blnoLocalChargeService.getBlNoCntrInfo(blId));
    }

    @Operation(summary = "local charge 计算")
    @PostMapping("/calcute")
    @OperateLog(name = "local charge 计算", type = OperateTypeEnum.UPDATE)
    @PreAuthorize("@ss.hasPermission({'doc:caculate:calculateSurcharge','doc:agentslocal:calculateSurcharge'})")
    public CommonResult<List<BlnoLocalChargeResultVO>> calcauteLocalCharge(@RequestBody BlnoLocalChargeCalcauteVO blnoLocalChargeCalcauteVo) {
        return CommonResult.success(blnoLocalChargeService.calcauteLocalCharge(blnoLocalChargeCalcauteVo.getBlIds(), blnoLocalChargeCalcauteVo.getImExType(), blnoLocalChargeCalcauteVo.getCurrentPort(), blnoLocalChargeCalcauteVo.getCodeMigration()));
    }

    @Operation(summary = "local charge add/copy")
    @PostMapping("/add")
    @OperateLog(name = "local charge add/copy", type = OperateTypeEnum.UPDATE)
    @PreAuthorize("@ss.hasPermission({'doc:caculate:create','doc:caculate:copyAdd','doc:agentslocal:create','doc:agentslocal:copyAdd'})")
    public CommonResult<Void> addLocalCharge(@Valid @RequestBody BlnoLocalChargeAddReqVO blnoLocalChargeAddReqVO) {
        blnoLocalChargeService.addLocalCharge(blnoLocalChargeAddReqVO);
        return CommonResult.success();
    }

    @Operation(summary = "local charge 修改")
    @PostMapping("/update")
    @PreAuthorize("@ss.hasPermission({'doc:caculate:update','doc:agentslocal:update'})")
    @OperateLog(name = "local charge 修改", type = OperateTypeEnum.UPDATE)
    public CommonResult<Void> updateLocalCharge(@RequestBody BlnoLocalChargeDO blnoLocalChargeDO) {
        blnoLocalChargeService.updateLocalCharge(blnoLocalChargeDO);
        return CommonResult.success();
    }

    @Operation(summary = "local charge delete")
    @GetMapping("/del/{id}")
    @OperateLog(name = "local charge delete", type = OperateTypeEnum.DELETE)
    @PreAuthorize("@ss.hasPermission({'doc:caculate:delete','doc:agentslocal:delete'})")
    public CommonResult<Void> deleteLocalCharge(@PathVariable("id") Long id) {
        blnoLocalChargeMapper.deleteById(id);
        return CommonResult.success();
    }

    @Operation(summary = "推送财务")
    @PostMapping("/account/{imExType}")
    @OperateLog(name = "local charge 推送财务", type = OperateTypeEnum.UPDATE)
    @PreAuthorize("@ss.hasPermission({'doc:caculate:toAccountcharge','doc:agentslocal:toAccountcharge'})")
    public CommonResult<Void> toAccount(@PathVariable("imExType") String imExType, @RequestBody List<Long> ids) {
        blnoLocalChargeService.toAccount(imExType, ids);
        return CommonResult.success();
    }
}
